package com.clkj.xiuzheng.dao.shangcheng;

import com.clkj.xiuzheng.pojo.shangcheng.ProductCart;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @author yawang
 * @create 2024/05/15 14:55:14
 **/
@Repository
public interface ProductCartMapper extends Mapper<ProductCart> {

    @Update("if exists (select * from t_xz_productCart where product_id = #{productId} and format_id = #{formatId} and user_id = #{userId}) " +
            " update t_xz_productCart set cart_num +=#{cartNum} where product_id = #{productId} and format_id = #{formatId} and user_id = #{userId}  " +
            "else insert into t_xz_productCart values (#{productId},#{formatId},#{cartNum},#{cartPrice},#{userId},#{factoryId}) ")
    void addOrUpdate(ProductCart cart);

    @Select("select a.*,b.product_name,b.product_image,c.format_name,c.product_price,c.product_score,c.product_num,c.post_num from t_xz_productCart a left join t_xz_product b on a.product_id = b.product_id " +
            "left join t_xz_productFormat c on a.format_id = c.format_id " +
            "where a.user_id = #{userId}")
    List<ProductCart> listCart(@Param("userId")Integer userId);
}
